package cn.tedu;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo02 {
    public static void main(String[] args) throws SQLException {
        //创建一个数据库连接对象  异常抛出
        Connection conn = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai",
                "root","root"
        );
        //新建用户输入
        Scanner scan = new Scanner(System.in);
        System.out.println("输入英雄名");
        String line = scan.nextLine();
        System.out.println("输入价格");
        double price = scan.nextDouble();
        //创建执行SQL语句的对象
        Statement s = conn.createStatement();

        s.executeUpdate("insert into hero values(null,'"+line+"',"+price+")");
        System.out.println("添加完成");
        conn.close();
    }
}
